<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="单据编号" prop="documentNumber">
        <el-input
          v-model="queryParams.documentNumber"
          placeholder="请输入单据编号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需求日期" prop="needTime">
        <el-date-picker
          v-model="queryParams.needTime"
          size="mini"
          style="width: 200px"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="测算人员" prop="updateUserName">
        <el-input
          v-model="queryParams.updateUserName"
          placeholder="请输入测算人员"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据状态" prop="documentStatus">
        <el-select v-model="queryParams.documentStatus" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="班次" prop="timeShiftId">
        <el-select   v-model="queryParams.timeShift"  placeholder="请选择"  >
          <el-option
            v-for="item in timeShiftList"
            :key="item.timeShiftId"
            :label="item.timeShiftName"
            :value="item.timeShiftName"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getWorkerNeedList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="operationNeedList" >
<!--      <el-table-column type="index" width="150" align="center"/>-->
      <el-table-column label="用工需求id" v-if="show" prop="workerNeedId" width="150"/>
      <el-table-column label="单据编号" prop="documentNumber" min-width="100" align="center"/>
      <el-table-column label="需求日期" prop="needTime" :show-overflow-tooltip="true" width="120" align="center" >
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.needTime, "{y}-{m}-{d}") }}</span>
      </template>
      </el-table-column>
      <el-table-column label="班次" align="center" prop="timeShift" width="80" />
      <el-table-column label="测算人员" prop="updateUserName" :show-overflow-tooltip="true" width="120" align="center"/>
      <el-table-column label="单据状态" prop="documentStatus" width="120" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.documentStatus == 0">待测算</div>
          <div v-else-if="scope.row.documentStatus == 1">待审核</div>
          <div v-else-if="scope.row.documentStatus == 2">审核通过</div>
          <div v-else-if="scope.row.documentStatus == 3">单据作废</div>
        </template>
      </el-table-column>
      <el-table-column label="备注" prop="remark" width="200" align="center"/>
      <el-table-column label="测算时间"  prop="updateTime" width="200" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="160" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope" v-if="scope.row.userId !== 1">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleView(scope.row)" v-hasPermi="['job:operationNeed:detail']">详情</el-button>
          <el-button v-if="scope.row.documentStatus < 2" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['job:operationNeed:edit']">测算</el-button>
          <el-button v-if="scope.row.documentStatus == 1" size="mini" type="text" icon="el-icon-edit" @click="handleAudit(scope.row)" v-hasPermi="['job:operationNeed:check']">审核</el-button>
          <el-button v-if="scope.row.documentStatus < 2" size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['job:operationNeed:delete']">作废</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getWorkerNeedList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核结果">
                <el-radio-group v-model="form.documentStatus">
                  <el-radio :label="2">通过</el-radio>
                  <el-radio :label="0">不通过</el-radio>
                </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="备注">-->
<!--              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getWorkerNeedList , deleteWorkerNeed , auditWorkerNeed } from "@/api/job/workerNeed/workerNeed";
import { getTimShiftInfo} from "@/api/job/scheme";
export default {
  name: "attendanceGroup",
  created() {
    this.getWorkerNeedList();
    this.getTimShiftInfo();
  },
  data() {
    return {
      //隐藏id列
      show:false,
      //signUpLoading:true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      operationNeedList: [],
      timeShiftList :[],
      options: [
        { value: '0', label: '待测算' },
        { value: '1', label: '待审核' },
        { value: '2', label: '审核通过' },
        { value: '3', label: '单据作废' }
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      signUp:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        documentNumber:undefined,
        needTime:undefined,
        updateUserName:undefined,
        documentStatus:undefined
      },
      // 表单参数
      form: {
        workerNeedId:undefined,
        //remark:undefined,
        documentStatus:undefined,
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },

  methods: {
    /** 获取用工需求列表 */
    getWorkerNeedList() {
      this.loading = true;
      getWorkerNeedList(this.queryParams).then(
        response => {
          this.operationNeedList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    handleView(row) {
      this.$router.push({path:"/personnel/staffMember/workerNeedDetail",query:{workerNeedId:row.workerNeedId}});
    },
    handleUpdate(row){
      this.$router.push({path:"/personnel/staffMember/workerNeedUpdate",query:{workerNeedId:row.workerNeedId}});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workerNeedId = row.workerNeedId || this.ids;
      this.$confirm('是否确认作废的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteWorkerNeed(workerNeedId);
        }).then(() => {
          this.getWorkerNeedList();
          this.msgSuccess("作废成功");
        }).catch(() => {});
    },
    /**审核按钮操作*/
    handleAudit(row){
      this.form.workerNeedId = row.workerNeedId;
      this.open = true;
      this.title = "审核";
    },
    // 表单重置
    reset() {
      this.form = {
        documentNumber:undefined,
        needTime:undefined,
        updateUserName:undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getWorkerNeedList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    submitForm(){
      auditWorkerNeed(this.form).then(es=>{
        this.msgSuccess(es.msg);
        this.open = false;
        this.getWorkerNeedList()
      })
    .catch(()=>{
      this.msgError("审核失败");
    })},
    cancel(){
      this.open = false;
      this.form.workerNeedId=undefined;
    },

    //方法区
     getTimShiftInfo(){
      getTimShiftInfo().then(
        response => {
          this.timeShiftList= response.rows;

        }
      );
    },



  }
};
</script>
